export function query(el) {
  if (typeof el === "string") {
    return document.querySelector(el) || document.createElement("div");
  }
  return el;
}

export function cached(fn) {
  const cache = Object.create(null);
  return function (str) {
    return cache[str] || (cache[str] = fn(str));
  };
}

export function noop() { }

export function no() {
  return false;
}

const camelizeRE = /-(\w)/g;
export const camelize = cached((str) =>
  str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ""))
);

const _toString = Object.prototype.toString;
export function isPlainObject(obj) {
  return _toString.call(obj) === "[object Object]";
}

export function extend(to, from) {
  for (const key in from) {
    to[key] = from[key];
  }
  return;
}

const hasOwnProperty = Object.prototype.hasOwnProperty;
export function hasOwn(obj, key) {
  return hasOwnProperty.call(obj, key);
}

const primitiveTypes = ["string", "number", "symbol", "boolean"];
export function isPrimitive(value) {
  return primitiveTypes.includes(typeof value);
}

export function isDef(v) {
  return v !== undefined && v !== null;
}

export function isUndef(v) {
  return v === undefined || v === null;
}

export function makeMap(str, expectsLowerCase) {
  const map = Object.create(null);
  const list = str.split(",");
  for (let val of list) {
    map[val] = true;
  }
  return expectsLowerCase ? (val) => map[val.toLowerCase()] : (val) => map[val];
}
